Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

216
Visualizações
Google Script - How to add a function in value="" in HTML with a JS function?

So it's my first post ever on StackOverflow, so sorry if I tell something weird:

So, I would like to display the date from the function Today() in my input with the id "file_name" (so, it will be like a default value):

webAppBoot.html

<!DOCTYPE html>
<html>

<head>
  <?!= include('WebAppBoot-css'); ?>
</head>

<body>
    <form>
        <div class="input-field col s6">
          <input id="file_name" type="text" class="validate">
          <label for="file_name">File name</label>
        </div>
    </form>
<?!= include('WebAppBoot-js'); ?>
</body>

</html>

index.gs

function doGet(request) {
  return HtmlService.createTemplateFromFile('WebAppBoot')
      .evaluate();
}

function include(filename) {
  return HtmlService.createHtmlOutputFromFile(filename)
      .getContent();
}

I know that I can totally write the function Today() from this file WebAppBoot-js.html

<script>
    document.getElementById("file_name").value = google.script.run.Today();    
</script>

But I prefer to add it from this file : functions.gs

  function Today() {
  var today = new Date();
  var dd = String(today.getDate()).padStart(2, '0');
  var mm = String(today.getMonth() + 1).padStart(2, '0')
  var yyyy = today.getFullYear();
  return mm + '/' + dd + '/' + yyyy;
}

So, as I tried, it's not working as you can see: undefined value

But I can still see that the function is working with a Logger.log(Today()) function So, to resume, in definitive, I would like to have that when we open the form:Final result

Can you help me ? Thank you

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda